<template>
  <div id="reg">
    <div class="header">
      <a href="/index"
        ><img src="http://1.117.75.96:8080/login/logo.png" alt=""
      /></a>
    </div>
    <div class="containers">
      <div class="rightbox">
        <form action="" class="login">
          <h2>注册</h2>
          <p class="part">
            <input
              type="text"
              name="username"
              v-model="addFrom.username"
              placeholder="用户名"
            />
          </p>
          <p class="part">
            <input
              type="password"
              name="password"
              v-model="addFrom.password"
              placeholder="密码"
            />
          </p>
          <p class="part">
            <input
              type="text"
              name="phone"
              v-model="addFrom.phone"
              placeholder="电话号码"
            />
          </p>
          <div class="checked">
            性别:
            <input
              type="radio"
              name="sex"
              value="男"
              v-model="addFrom.sex"
            /><span style="width: 20px">男</span>
            <input
              type="radio"
              name="sex"
              value="女"
              v-model="addFrom.sex"
            /><span style="width: 20px">女</span>
          </div>
          <p class="part">
            <input
              type="number"
              name="age"
              v-model="addFrom.age"
              placeholder="年龄"
            />
          </p>
          <p class="address">
            <input
              type="text"
              name="address"
              v-model="addFrom.address"
              placeholder="家庭地址"
            />
          </p>
          <div class="btn" @click="reg">注册</div>
          <div class="more">
            <router-link to="/login" class="reg">返回密码登录</router-link>
          </div>
        </form>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ElMessage } from "element-plus";
import { addUser } from "@/api/userApi.js";
import { ref } from "vue-demi";
import { set } from "lodash";
import { useRouter } from "vue-router";

let router=useRouter()

let addFrom = ref({
  username: "",
  password: "",
  sex: "男",
  address: "",
  age: null,
  phone: "",
});
//注册
async function reg() {
  if (addFrom.value.username && addFrom.value.password) {
    let res = await addUser(addFrom.value);
    console.log(res);
    if (!res) return;
    ElMessage({
      message: "注册成功!!即将跳转到登录页",
      type: "success",
    });
    setTimeout(() => {router.push({name:'Login'})}, 1000);
  } else {
    ElMessage.error("用户名和密码不能为空!!");
  }
}
</script>

<style lang="less" scoped>
.header {
  width: 1413px;
  padding: 0 125px;
  margin: 0 auto 44px;
  box-sizing: border-box;

  a {
    display: inline-block;

    img {
      width: 519px;
      height: 84px;
    }
  }
}
.rightbox {
  display: inline-block;
  vertical-align: middle;

  .login {
    position: relative;
    display: inline-block;
    padding: 0 46px;
    width: 478px;
    text-align: left;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0px 0px 24px 0px rgb(0 0 0 / 4%);

    h2 {
      padding-top: 50px;
      font-size: 34px;
      line-height: 46px;
      font-family: HarmonyOS Sans SC Medium;
      font-weight: 600;
      color: #000;
      margin-bottom: 34px;
    }

    .part {
      input {
        display: block;
        padding: 0 20px;
        width: 100%;
        height: 64px;
        font-size: 22px;
        background: #f7f7f7;
        border-radius: 12px;
        border: none;
        outline: none;
        box-shadow: none;
        margin-bottom: 16px;
        box-sizing: border-box;
      }
    }

    .checked {
      display: flex;
      padding-top: 8px;
      height: 21px;

      p {
        display: inline-block;
        vertical-align: top;
        line-height: 21px;
        font-size: 16px;
        color: #6a6a6a;
        margin-left: 4px;

        span {
          display: inline-block;
          vertical-align: top;
          font-size: 16px;
          color: #000;
          text-decoration: none;
        }
      }
    }

    .btn {
      width: 100%;
      height: 64px;
      line-height: 64px;
      font-size: 24px;
      color: #fff;
      font-family: HarmonyOS Sans SC Medium;
      font-weight: 600;
      text-align: center;
      background: #1f7efe;
      border-radius: 12px;
      margin-top: 24px;
      cursor: pointer;
    }

    .more {
      margin-top: 8px;
      width: 100%;
      overflow: hidden;

      a {
        font-size: 22px;
        color: #535353;
        font-family: HarmonyOS Sans SC Medium;
        font-weight: 600;
        line-height: 30px;
        cursor: pointer;
      }

      .reg {
        color: #1f7efe;
        float: right;
      }

      .forget {
        float: left;
      }
    }

    .other {
      padding: 80px 0 40px;
      width: 100%;
      text-align: center;
      font-size: 24px;
      line-height: 32px;
      font-weight: 600;
      color: #c3c4c4;

      img {
        width: 56px;
        height: 56px;
        margin: 16px auto 0;
        cursor: pointer;
      }
    }

    .rightTop {
      position: absolute;
      right: 0;
      top: 0;
      width: 136px;
      height: 136px;
      z-index: 1;
      cursor: pointer;

      img {
        width: 100%;
        height: 100%;
      }
    }
  }
}
.containers {
  width: 1413px;
  margin: auto;
  font-size: 0;
  text-align: center;
  .rightbox {
    background-color: antiquewhite;
    border-radius: 20px;
    .login {
      .checked {
        margin-top: 20px;
        margin-bottom: 30px;
        input {
          width: 20px;
        }
        span {
          font-size: 20px;
          margin-right: 5px;
        }
      }
      .more {
        margin-bottom: 40px;
      }
      .part {
        input {
          margin-bottom: 20px !important;
        }
      }
    }
    .address {
      input {
        width: 100%;
        height: 70px;
        margin-left: -2px;
        padding-left: 20px;
        box-sizing: border-box;
        font-size: 20px;
        border-radius: 12px;
      }
    }
  }
}
</style>
